//
//  RBAddressListCell.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/15.
//

#import "RBAddressListCell.h"
#import "UIView+RBAdd.h"
#import "RanTool.h"
#import "RBThemeConfig.h"
#import "RBDefine.h"
#import <UIColor+YYAdd.h>

@interface RBAddressListCell()

@property(nonatomic, strong)IBOutlet UILabel*nameL;
@property(nonatomic, strong)IBOutlet UILabel *defaultL;
@property(nonatomic, strong)IBOutlet UILabel*addressL;
@property(nonatomic, strong)IBOutlet UIImageView *defaultImgView;

@property(nonatomic, strong) RBCellModel *cellModel;

@end

@implementation RBAddressListCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self zoomSubViewsWithSelf];
}

- (void)setCellModel:(RBCellModel *)cellModel
{
    _cellModel = cellModel;
    RBAddressListModel *model = cellModel.cellData;
    self.nameL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(16) weight:UIFontWeightMedium] color:[UIColor colorWithHexString:@"#222222"] string:model.name];
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[RBThemeConfig textLightBlackColor] string:@"　"];
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[RBThemeConfig textLightBlackColor] string:model.mobile];
    }];
    self.defaultL.hidden = model.moren.intValue != 1;
    self.addressL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(14)] color:[UIColor colorWithHexString:@"454545"] string:[NSString stringWithFormat:@"%@ %@ %@ %@", model.province, model.city, model.area, model.address] lineSpacing:Zoom(7)];
    }];
    if ([model.moren isEqualToString:@"1"]) {
        self.defaultImgView.image = [UIImage imageNamed:@"addressListDefault"];
    } else {
        self.defaultImgView.image = [UIImage imageNamed:@"unsel"];
    }
}

#pragma mark - Event

- (IBAction)defaultBtnTapped:(id)sender
{
    if(self.cellModel.eventBlock1)
    {
        self.cellModel.eventBlock1(0, 0, self.cellModel.cellData);
    }
}

- (IBAction)editBtnTapped:(id)sender
{
    if(self.cellModel.eventBlock1)
    {
        self.cellModel.eventBlock1(1, 0, self.cellModel.cellData);
    }
}

@end
